# -*- conding:UTF-8 -*-

'''
@ Project: p7_flask
@ File: jwt_util.py
@ Author: 师路遥
@ Date：2022/6/6 18:13

'''

import jwt
from flask import current_app

def generate_token(payload,expiry,algorithm='HS256'):
    """生成token"""
    key = current_app.config.get('SECRET_KEY')
    print('>>>>>>>>>>>>>>>>>>>>',key)
    if 'expiry' not in payload:
        payload['expiry']=expiry
    try:
        token = jwt.encode(payload, key, algorithm)
        return token
    except Exception as e:
        print('generate_token error', e)
        return e


def check_token(token):
    """校验token"""
    key = current_app.config.get('SECRET_KEY')
    payload = jwt.decode(token,key,algorithms='HS256')
    return payload
